package com.my_test.webmagic.config;

import com.my_test.webmagic.webmagic_modules.WebMagicEsPipeline;
import com.my_test.webmagic.webmagic_modules.WebMagicProcessor;
import com.my_test.webmagic.module.service.UserService;
import com.my_test.webmagic.webmagic_modules.WebMagicMysqlPipeline;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.scheduler.RedisScheduler;

import javax.annotation.Resource;

/**
 * @author zhangyalin@act-telecom.com
 * @date 2019-05-23 16:54
 **/
@Component
@Order(2)
public class MyApplicationRun implements ApplicationRunner {

    @Resource
    private UserService userService;
    @Resource
    private WebMagicProcessor webMagicProcessor;
    @Resource
    private WebMagicMysqlPipeline webMagicMysqlPipeline;
    @Resource
    private RedisScheduler redisScheduler;
    @Resource
    private WebMagicEsPipeline webMagicEsPipeline;

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        Spider.create(webMagicProcessor).setScheduler(redisScheduler).addPipeline(webMagicMysqlPipeline).addPipeline(webMagicEsPipeline).addUrl("https://tieba.baidu.com/f?kw=diy").thread(5).run();
        Spider.create(webMagicProcessor).setScheduler(redisScheduler).addPipeline(webMagicMysqlPipeline).addPipeline(webMagicEsPipeline).addUrl("http://tieba.baidu.com/f/index/forumclass").thread(5).start();
    }
}
